package com.sskj.award.ui.activity;

import android.annotation.SuppressLint;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.award.R;
import com.sskj.award.R2;
import com.sskj.award.bean.AirDropBean;
import com.sskj.award.presenter.AirDropPresenter;
import com.sskj.common.base.App;
import com.sskj.common.util.ClickUtil;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @ClassName: AirDropActivity
 * @Description: java类作用描述:空投区
 * @Author: yuanlin
 * @Date: 2019/7/12 15:31
 */
@Route(path = RConfig.SUPER_SUPER_AIR_DROP)
public class AirDropActivity extends BaseActivity<AirDropPresenter> {

    @BindView(R2.id.llBtLeft)
    LinearLayout llBtLeft;
    @BindView(R2.id.tvLeft)
    TextView tvLeft;
    @BindView(R2.id.viewSplit1)
    View viewSplit1;
    @BindView(R2.id.llBtRight)
    LinearLayout llBtRight;
    @BindView(R2.id.tvRight)
    TextView tvRight;
    @BindView(R2.id.viewSplit2)
    View viewSplit2;
    @BindView(R2.id.tvShowZhiTuiCount)
    TextView tvShowZhiTuiCount;
    @BindView(R2.id.tvShowZhiTuiPlatformCount)
    TextView tvShowZhiTuiPlatformCount;
    @BindView(R2.id.tvShowZhiTuiTotalCount)
    TextView tvShowZhiTuiTotalCount;
    @BindView(R2.id.tvShowTeamCount)
    TextView tvShowTeamCount;
    @BindView(R2.id.tvShowTeamSuperPlatformCount)
    TextView tvShowTeamSuperPlatformCount;
    @BindView(R2.id.tvShowTeamTotalCount)
    TextView tvShowTeamTotalCount;

    private ArrayList<Fragment> fragments;

    @Override
    protected int getLayoutId() {
        return R.layout.super_layout_activity_super_airdrop;
    }

    @Override
    public AirDropPresenter getPresenter() {
        return new AirDropPresenter();
    }

    @Override
    protected void dealFirstSaveInstance(Bundle savedInstanceState) {
//        super.dealFirstSaveInstance(savedInstanceState);
        FragmentManager mManager = getSupportFragmentManager();
        if (savedInstanceState != null) {
            List<Fragment> fragments = mManager.getFragments();
            FragmentTransaction fragmentTransaction = mManager.beginTransaction();
            for (int i = 0; i < fragments.size(); i++) {
                fragmentTransaction.remove(fragments.get(i));
            }
            fragmentTransaction.commitAllowingStateLoss();
        }
    }

    @Override
    protected void initView() {
        super.initView();
        setTitle(App.INSTANCE.getString(R.string.super_airDropActivity1));
        mPresenter.getAirData();

        fragments = new ArrayList<>();
        fragments.add((Fragment) ARouter.getInstance().build(RConfig.SUPER_SUPER_DETAILS_ASSETS).navigation());
        fragments.add((Fragment) ARouter.getInstance().build(RConfig.SUPER_SUPER_COMMUNITY_PERFORMANCE).navigation());
        getSupportFragmentManager()
                .beginTransaction()
                .add(R.id.frameLayout, fragments.get(0))
                .add(R.id.frameLayout, fragments.get(1))
                .hide(fragments.get(1))
                .show(fragments.get(0))
                .commitAllowingStateLoss();

        ClickUtil.click(llBtLeft, () -> {
            tvLeft.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
            tvLeft.setTextColor(getResources().getColor(R.color.super_text_blue));
            tvRight.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
            tvRight.setTextColor(getResources().getColor(R.color.super_8e9));
            viewSplit1.setVisibility(View.VISIBLE);
            viewSplit2.setVisibility(View.GONE);

            getSupportFragmentManager()
                    .beginTransaction()
//                    .add(R.id.frameLayout, fragments.get(0))
                    .hide(fragments.get(1))
                    .show(fragments.get(0))
                    .commitAllowingStateLoss();

        });
        ClickUtil.click(llBtRight, () -> {
            tvLeft.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
            tvLeft.setTextColor(getResources().getColor(R.color.super_8e9));
            tvRight.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
            tvRight.setTextColor(getResources().getColor(R.color.super_text_blue));
            viewSplit1.setVisibility(View.GONE);
            viewSplit2.setVisibility(View.VISIBLE);
            getSupportFragmentManager()
                    .beginTransaction()
//                    .add(R.id.frameLayout, fragments.get(1))
                    .hide(fragments.get(0))
                    .show(fragments.get(1))
                    .commitAllowingStateLoss();
        });
    }

    @SuppressLint("SetTextI18n")
    public void getAirDataSuccess(AirDropBean data) {
        if (data == null) {
            return;
        }
        tvShowZhiTuiCount.setText(data.getCommunity_level());
        tvShowZhiTuiPlatformCount.setText(data.getTui_count()+ App.INSTANCE.getString(R.string.super_airDropActivity2));
        tvShowZhiTuiTotalCount.setText(data.getTotal_count()+App.INSTANCE.getString(R.string.super_airDropActivity2));
        tvShowTeamCount.setText(data.getLevel1_count()+App.INSTANCE.getString(R.string.super_airDropActivity2));
        tvShowTeamSuperPlatformCount.setText(data.getLevel2_count()+App.INSTANCE.getString(R.string.super_airDropActivity2));
        tvShowTeamTotalCount.setText(data.getLevel3_count()+App.INSTANCE.getString(R.string.super_airDropActivity2));
    }
}
